package net.lummox.model;

import net.lummox.common.RequestedAction;
import net.lummox.common.TurnAction;

public class Turn {
	private RequestedAction expectedAction;
	private TurnAction action;
	
	private String leftLetter;
    private String partOfWord;
    private String rightLetter; 

	public String getLeftLetter() {
		return leftLetter;
	}

	public void setLeftLetter(String leftLetter) {
		this.leftLetter = leftLetter;
	}

	public String getPartOfWord() {
		return partOfWord;
	}

	public void setPartOfWord(String partOfWord) {
		this.partOfWord = partOfWord;
	}

	public String getRightLetter() {
		return rightLetter;
	}

	public void setRightLetter(String rightLetter) {
		this.rightLetter = rightLetter;
	}

	public TurnAction getAction() {
		return action;
	}

	public void setAction(TurnAction action) {
		this.action = action;
	}

	public RequestedAction getExpectedAction() {
		return expectedAction;
	}

	public void setExpectedAction(RequestedAction expectedAction) {
		this.expectedAction = expectedAction;
	}
	
	public String getOpponentPartOfWord() {
		return (leftLetter == null ? "" : leftLetter)
				+ (partOfWord == null ? "" : partOfWord)
				+ (rightLetter == null ? "" : rightLetter);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((action == null) ? 0 : action.hashCode());
		result = prime * result
				+ ((expectedAction == null) ? 0 : expectedAction.hashCode());
		result = prime * result
				+ ((leftLetter == null) ? 0 : leftLetter.hashCode());
		result = prime * result
				+ ((partOfWord == null) ? 0 : partOfWord.hashCode());
		result = prime * result
				+ ((rightLetter == null) ? 0 : rightLetter.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Turn other = (Turn) obj;
		if (action != other.action)
			return false;
		if (expectedAction != other.expectedAction)
			return false;
		if (leftLetter == null) {
			if (other.leftLetter != null)
				return false;
		} else if (!leftLetter.equals(other.leftLetter))
			return false;
		if (partOfWord == null) {
			if (other.partOfWord != null)
				return false;
		} else if (!partOfWord.equals(other.partOfWord))
			return false;
		if (rightLetter == null) {
			if (other.rightLetter != null)
				return false;
		} else if (!rightLetter.equals(other.rightLetter))
			return false;
		return true;
	}
}
